// Copyright (C) 2006 Igor Zelmanovich <izwebfilemanager@gmail.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;

namespace IZ.WebFileManager
{
    //public delegate void RenameCancelEventHandler(object sender, RenameCancelEventArgs e);
    //public class RenameCancelEventArgs : FileManagerCancelEventArgs
    //{
    //    internal RenameCancelEventArgs() { }
    //}

    //public delegate void RenameEventHandler(object sender, RenameEventArgs e);
    //public class RenameEventArgs : EventArgs
    //{
    //    internal RenameEventArgs() { }
    //}

    //public delegate void ExecuteCommandEventHandler(object sender, ExecuteCommandEventArgs e);
    public class ExecuteCommandEventArgs : CommandEventArgs
    {
        private readonly Collection<FileManagerItemInfo> items = new Collection<FileManagerItemInfo>();
        private string clientScript = "";

        internal ExecuteCommandEventArgs(string commandName, object argument) : base(commandName, argument)
        {
        }

        public string ClientScript
        {
            get { return clientScript == null ? String.Empty : clientScript; }
            set { clientScript = value; }
        }

        public Collection<FileManagerItemInfo> Items
        {
            get { return items; }
        }
    }

    //public delegate void RenameCancelEventHandler(object sender, RenameCancelEventArgs e);
    public class RenameCancelEventArgs : FileManagerCancelEventArgs
    {
        internal RenameCancelEventArgs()
        {
        }

        public FileManagerItemInfo FileManagerItem { get; internal set; }

        public string NewName { get; set; }
    }

    //public delegate void RenameEventHandler(object sender, RenameEventArgs e);
    public class RenameEventArgs : EventArgs
    {
        internal RenameEventArgs()
        {
        }

        public FileManagerItemInfo FileManagerItem { get; internal set; }
    }


    //public delegate void NewFolderCancelEventHandler(object sender, NewFolderCancelEventArgs e);
    public class NewFolderCancelEventArgs : FileManagerCancelEventArgs
    {
        internal NewFolderCancelEventArgs()
        {
        }

        public FileManagerItemInfo DestinationDirectory { get; internal set; }
    }

    //public delegate void NewFolderEventHandler(object sender, NewFolderEventArgs e);
    public class NewFolderEventArgs : EventArgs
    {
        internal NewFolderEventArgs()
        {
        }

        public FileManagerItemInfo NewFolder { get; internal set; }
    }

    //public delegate void NewDocumentEventHandler(object sender, NewDocumentEventArgs e);
    public class NewDocumentEventArgs : EventArgs
    {
        internal NewDocumentEventArgs()
        {
        }

        public NewDocumentTemplate Template { get; internal set; }

        public FileManagerItemInfo NewDocument { get; internal set; }
    }

    //public delegate void NewDocumentCancelEventHandler(object sender, NewDocumentCancelEventArgs e);
    public class NewDocumentCancelEventArgs : FileManagerCancelEventArgs
    {
        internal NewDocumentCancelEventArgs()
        {
        }

        public NewDocumentTemplate Template { get; internal set; }

        public FileManagerItemInfo DestinationDirectory { get; internal set; }
    }

    public enum SelectedItemsAction
    {
        Move,
        Copy,
        Delete
    }

    public class SelectedItemsActionCancelEventArgs : FileManagerCancelEventArgs
    {
        private readonly SelectedItemsAction _action;

        private readonly Collection<FileManagerItemInfo> items = new Collection<FileManagerItemInfo>();

        internal SelectedItemsActionCancelEventArgs(SelectedItemsAction action)
        {
            _action = action;
        }

        public SelectedItemsAction Action
        {
            get { return _action; }
        }

        public Collection<FileManagerItemInfo> SelectedItems
        {
            get { return items; }
            //internal set { items = value; }
        }

        public FileManagerItemInfo DestinationDirectory { get; internal set; }
    }

    public class SelectedItemsActionEventArgs : EventArgs
    {
        internal SelectedItemsActionEventArgs()
        {
        }
    }

    //public delegate void UploadFileCancelEventHandler(object sender, UploadFileCancelEventArgs e);
    public class UploadFileCancelEventArgs : FileManagerCancelEventArgs
    {
        private string saveName;

        internal UploadFileCancelEventArgs()
        {
        }

        public FileManagerItemInfo DestinationDirectory { get; internal set; }

        public HttpPostedFile PostedFile { get; internal set; }

        public string SaveName
        {
            get { return (saveName == null || saveName.Length == 0) ? Path.GetFileName(PostedFile.FileName) : saveName; }
            set { saveName = value; }
        }
    }

    //public delegate void UploadFileEventHandler(object sender, UploadFileEventArgs e);
    public class UploadFileEventArgs : EventArgs
    {
        internal UploadFileEventArgs()
        {
        }

        public FileManagerItemInfo UploadedFile { get; internal set; }
    }

    public class DownloadFileCancelEventArgs : CancelEventArgs
    {
        public FileManagerItemInfo DownloadFile { get; internal set; }
    }

    public class FileManagerCancelEventArgs : CancelEventArgs
    {
        public string ClientMessage { get; set; }
    }
}